package com.pug.controller.hotel;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pug.controller.BaseController;
import com.pug.pojo.Hotel;
import com.pug.service.user.UserServiceImpl;
import com.pug.service.userfav.IUserFavHotelService;
import com.pug.utils.fn.asserts.Vsserts;
import com.pug.vo.UserHotelFavSearchVo;
import com.pug.vo.UserHotelFavVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Author: lqm
 * create: 2022/4/28 21:12
 * Lover: lqx
 *
 * @see
 */
@RestController
public class UserFavHotelController extends BaseController {
    //用户对酒店收藏
    @Autowired
    private IUserFavHotelService userFavHotelService;
    @Resource
    UserServiceImpl userService;

    /**
     * 查询用户的收藏的酒店信息
     *
     * @param userHotelFavSearchVo
     * @return
     */
    @PostMapping("/userfav/hotel/load")
    public Page<Hotel> findUserFavHotelsPage(@RequestBody UserHotelFavSearchVo userHotelFavSearchVo) {
        return userFavHotelService.findUserFavHotelsPage(userHotelFavSearchVo);
    }

    /**
     * 用户收藏酒店
     *
     * @param userHotelFavVo
     * @return
     */
    @PostMapping("/userfav/hotel/save")
    public boolean savaUserFavHotel(@RequestBody UserHotelFavVo userHotelFavVo, HttpServletRequest request) {
        String authUserId = request.getHeader("AuthUserId");//这个其实是电话号码
        userHotelFavVo.setUserId(new Long(authUserId));
        Vsserts.isNullEx(userHotelFavVo.getHotelId(), "查无此酒店信息");
        return userFavHotelService.savaUserFavHotel(userHotelFavVo);
    }

    /**
     * 用户取消收藏
     *
     * @param userHotelFavVo
     * @return
     */
    @PostMapping("/userfav/hotel/remove")
    public boolean removeUserFavHotel(@RequestBody UserHotelFavVo userHotelFavVo) {
        Vsserts.isNullEx(userHotelFavVo.getHotelId(), "查无此酒店信息");
        return userFavHotelService.removeUserFavHotel(userHotelFavVo);
    }
}
